<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单管理列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>销售单号：</label>
                            <input type="text" name="orderNo"/>
                        </li>
                        <li>
                            <label>客户名称：</label>
                            <input type="text" name="receiver"/>
                        </li>
                        <li>
                            <label>联系电话：</label>
                            <input type="text" name="mobile"/>
                        </li>
                        <li class="select-time">
                            <label>销售时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginOrderTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endOrderTime]"/>
                        </li>
                        <li>
                            <label>收款方式：</label>
                            <select name="payWay" th:with="type=${@dict.getType('pay_way')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>物流公司：</label>
                            <select name="logistics" th:with="type=${@dict.getType('order_logistics')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>销售金额：</label>
                            <input type="text" name="amount"/>
                        </li>
                        <li>
                            <label>联系人：</label>
                            <input type="text" name="constact"/>
                        </li>
                        <li>
                            <label>商品摘要：</label>
                            <input type="text" name="summary"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="order:order:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="order:order:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="order:order:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="order:order:import">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="order:order:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-primary multiple disabled" onclick="print()" shiro:hasPermission="order:order:print">
                <i class="fa fa-print"></i> 打印
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
        <div class="columns columns-right btn-group pull-right" id="count"></div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('order:order:edit')}]];
    var removeFlag = [[${@permission.hasPermi('order:order:remove')}]];
    var payWayDatas = [[${@dict.getType('pay_way')}]];
    var logisticsDatas = [[${@dict.getType('order_logistics')}]];
    var prefix = ctx + "order/order";
    function print() {

//        var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
//        if (id.length == 0) {
//            $.modal.alertWarning("请至少选择一条记录");
//            return;
//        }
//         $.modal.open("打印订单", prefix+"/orderInfo"+"/"+id);


        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var ids = rows.join();
        var width = 800;
        var height = ($(window).height() - 50);
        var callback = function (index, layero) {
            var iframeWin = layero.find('iframe')[0];
            iframeWin.contentWindow.submitHandler(index, layero);
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "打印订单",
            content: prefix + "/orderInfo" + "?ids=" + ids,
            btn: ['打印', '关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            yes: callback,
            cancel: function (index) {
                return true;
            }
        });

    }

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/import",
            modalName: "订单管理",
            importTemplateUrl: prefix + "/importTemplate",
            responseHandler: responseHandler,
            columns: [{
                checkbox: true
            },
                {
                    field: 'orderId',
                    title: '',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '销售单号'
                },
                {
                    field: 'receiver',
                    title: '客户名称'
                },
                {
                    field: 'address',
                    title: '详细地址'
                },
                {
                    field: 'mobile',
                    title: '联系电话'
                },
                {
                    field: 'orderTime',
                    title: '销售时间'
                },
                {
                    field: 'payWay',
                    title: '收款方式',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(payWayDatas, value);
                    }
                },
                {
                    field: 'logistics',
                    title: '物流公司',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(logisticsDatas, value);
                    }
                },
                {
                    field: 'comment',
                    title: '备注'
                },
                {
                    field: 'amount',
                    title: '销售金额'
                },
                {
                    field: 'constact',
                    title: '联系人'
                },
                {
                    field: 'summary',
                    title: '商品摘要'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.orderId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    // 当所有数据被加载时触发处理函数
    function responseHandler(res) {
        var winMoneyTotal = res.msg;
        var html = "";
        html = "<span > 销售总金额：</span>"
        html += "<span style='color:red'>" + winMoneyTotal + "元</span>";
        $("#count").html(html);
    }

</script>
</body>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <!--<div class="mt10 pt5">-->
            <!--<input type="checkbox" id="updateSupport" name="updateSupport" title="如果订单已经存在，更新这条数据。"> 是否更新已经存在的订单数据-->
            <!--&nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i-->
            <!--class="fa fa-file-excel-o"></i> 下载模板</a>-->
            <!--</div>-->
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

</html>